<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Exception;
use App\Tools\Mysqldump\Mysqldump;


class SettingController extends Controller {


	public function info(){


       return view('admin.setting.info',[]);

	}


	public function callbackdata(){

	    $list = DB::table('backup')->get();

		return view('admin.setting.callbackdata',['list'=>$list]);

	}

	public function  notice(){


		return view('admin.setting.notice',[]);
	}
	

	public function  sendmessage(){


		return view('admin.setting.sendmessage',[]);
	}


	public function  messageset(){

		return view('admin.setting.messageset',[]);

	}

	public function  article(){

		return view('admin.setting.article',[]);

	}


	public function backup(Response $response){

	    $data['filename'] = date("YmdHis",time()).'.sql';
	    $data['time'] = date("Y-m-d H:i:s",time());
		$res = $this->store($data['filename']);
        if($res == true){
            $path ='./backup/'.$data['filename'];
            $data['filesize'] = filesize($path);
            DB::table('backup')->insert($data);
            echo "<script language='javascript'>alert('备份成功');window.location.href='./callbackdata';</script>";
        }





	}


	 public function store($name)
    {

        try {
             $dump = new Mysqldump('mysql:host=localhost;dbname=telent', 'root', '123456');
             $bool = $dump->start('./backup/'.$name);
             return true;
        } catch (\Exception $e) {
            echo 'mysqldump-php error: ' . $e->getMessage();
        }

        return 1;
    }


}

?>